import type PageModel from '@/components/page-model/page-model.vue'
import { ref } from 'vue'

function usePageModel(editCb?: (payload: any) => void,relatedCb?: (payload?: any,isRelated?:boolean) => void) {
  const pageModelRef = ref<InstanceType<typeof PageModel>>()

  const handleAddNewClick = (isRelated?,relatedCb?) => {
    pageModelRef.value?.showModel(false,'',isRelated)
    relatedCb && relatedCb(isRelated)
  }
  const handleEditClick = (payload,isRelated?) => {
    pageModelRef.value?.showModel(true, payload,isRelated)
    editCb && editCb(payload)
    relatedCb && relatedCb(payload,isRelated)
  }
  return { pageModelRef, handleAddNewClick, handleEditClick }
}

export default usePageModel
